Repository navigation
feat: bounded background retry of failed feature fetches, async refresh_features - #174
Open
vazarkevych wants to merge 5 commits into
Open
vazarkevych wants to merge 5 commits into
vazarkevych wants to merge 5 commits into
Conversation
…sh_features A failed feature fetch was never retried by the SDK: the only retries were urllib3's immediate ones (disabled by the timeout change), 5xx and remote-eval POSTs got none, and the async initialize() made one attempt. - After a failed fetch the call returns at once with the best available features, and the fetch is retried in the background with delays of 1, 2, 4, 8, 16s (max_fetch_retries=5, fetch_retry_max_delay=16; 0 disables). Each retry logs "Feature fetch failed. Retry attempt n/N in Xms."; after the last one the SDK stops and keeps what it has. Retries never extend startup. - Sync GrowthBook: one daemon thread per instance at a time, stopped by destroy(). Covers constructor loads, load_features(), SSE-triggered and remote-eval loads; remote-eval retries rebuild the payload each attempt. The lazy per-evaluation refresh doesn't start retries, since the next evaluation already re-fetches. - Async GrowthBookClient: a failed initialize() still returns False; an asyncio task retries and, on success, installs the features and starts refreshing like a successful initialize(). close() cancels it. preload_remote_eval() retries in place, since its response is per user. - New GrowthBookClient.refresh_features(force_refresh=True): bypasses the cache and applies the result; in remote-eval mode it drops cached per-user responses. Sync already has load_features(force_refresh=True). - Options are validated at construction; new constructor parameters are appended last.
- Only connection errors, timeouts, 429 and 5xx are retried. The repository records the failure kind; a 401/403/404, an unusable body or a decryption failure is reported once, and stops a retry loop already running. Same in the async client's init retry; an exception from initialize() (a configuration error) is no longer retried either. - The sync retry loop moved into the shared feature_repo: one loop per (api_host, client_key), delivering through the feature-update callbacks. Per instance, an outage multiplied requests by the number of instances and each loop kept its instance alive. The loop stops early once every instance is destroyed. - preload_remote_eval() makes one attempt instead of retrying in place, which added the whole schedule to every preloading request during an outage. Sync remote eval isn't retried in the background either; both fall back to defaults and refetch on the next cache miss. - max_fetch_retries and fetch_retry_max_delay are appended after request_timeout so existing positional Options arguments keep their meaning; the field-order test now pins the whole released prefix.
…sh init from refresh_features - A retry success went through load_features, which notified every connection in the process, so other keys' instances got this key's flags. Route feature updates by (api_host, client_key), the same change as in feat/polling-interval: GrowthBook registers its callback with its key and loads/pollers notify with theirs; unkeyed callbacks still hear everything. - The retry loop kept going while any instance in the process was alive. It now stops once nothing on its key (or unkeyed) would receive the result. - refresh_features() after a failed initialize() applied the features but never registered the update callback or started refreshing. It now completes the initialization and cancels the pending retry. In remote-eval mode it returns False when nothing was flushed.
Confidence Score: 5/5
[Medium impact] The reviewed changes appear safe to merge; all four previous findings are addressed. Reviews (2) · Last reviewed commit: "fix: forget finished retry workers, canc..." · Reviewed by Greptile |
…ore updates after destroy - A finished fetch retry worker removes its own entry, so keys that once failed don't accumulate threads until stop_fetch_retries(). - Any successful initialization path (initialize(), the retry, refresh_features()) cancels a pending initial-load retry. - destroy() and feature-update delivery agree on liveness through the payload lock, so an update dispatched before destroy() can't repopulate the instance. - fetch_retry_max_delay rejects NaN and infinity.
Collaborator
Author
|
@greptile review |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What and why
A failed feature fetch was never retried. The only retries were urllib3's immediate ones, which the request-timeout change disables, so a 5xx or a dropped connection left the SDK on cache or defaults until the next refresh, and the async
initialize()made a single attempt.What changed
Feature fetch failed. Retry attempt n/N in Xms.), and after the last one the SDK stops. Retries never extend startup.(api_host, client_key)in the sharedfeature_repo, not per instance, so an outage doesn't multiply requests by the number of instances. The first failing instance's settings apply, and a finished loop is dropped so keys don't accumulate threads.(api_host, client_key), the same change as in feat: configurable polling interval, per-key pollers, refresh backoff #173. Callbacks registered without a key still receive every update.destroy()runs.initialize()still returnsFalse. A successful retry installs the features and starts refreshing. Any successful initialization (a retry, a laterinitialize()orrefresh_features()) cancels the pending retry, and so doesclose().preload_remote_eval()and the sync remote-eval load make one attempt; evaluations fall back to defaults and refetch on their own cache miss.GrowthBookClient.refresh_features(force_refresh=True):initialize(), a successful call completes the initialization and starts background refresh.force_refresh=Trueit drops the cached per-user responses.max_fetch_retries(default 5, 0 disables) andfetch_retry_max_delay(default 16s, must be finite), on bothGrowthBook(...)andOptions, validated at construction. Both are appended afterrequest_timeout, so existing positional arguments keep their meaning.Shares the callback routing change with #173. The code is identical in both, so whichever PR lands second merges cleanly there.
How to test
42 new tests in
tests/test_fetch_retry.py:initialize()retry, cancellation on a later successfulinitialize()and onclose();refresh_features, including completing a failedinitialize();test_request_timeout.pynow checks that all new fields come after the released ones.Full suite (with #169 and current
mainmerged): 2034 passed. The 2 mypy failures intest_typing.pycome from the local urllib3 version and happen without these changes too.Size
Relative to #169: production code +549 / −52, tests +789 / −12, README +62. About 1,400 lines, more than half of it tests.
Migration
None. Retries start only after a failed fetch and can be turned off with
max_fetch_retries=0.add_feature_update_callback(callback)without a key behaves as before.